package com.example.InetAddressDemos.tcp;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * @author Jason
 * @PACKAGE_NAME com.example.InetAddressDemos.tcp
 * @Description
 * @date 2023-12-18 20:55
 */
public class TcpClient {
    public static void main(String[] args) throws IOException {
        //TCP协议 发送数据
        //1.创建对象的同时会连接服务器
        //连接不上，代码报错
        Socket socket = new Socket("127.0.0.1", 10001);

        //2.从连接通道中获取输出流
        OutputStream os = socket.getOutputStream();
        //3.写出数据
        os.write("你好你好".getBytes());

        //4.适当资源
        os.close();
        socket.close();
    }

}
